package UserSum;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class User implements WritableComparable<User> {
    private String id;
    private int hour;
    private int num;
    private String date;
    public int compareTo(User o) {
        int a = o.id.compareTo(this.id);
        if (a==0){
            return this.num - o.num;
        }
        return a;
    }

    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(id);
        dataOutput.writeInt(hour);
        dataOutput.writeInt(num);
        dataOutput.writeUTF(date);
    }

    public void readFields(DataInput dataInput) throws IOException {
        id = dataInput.readUTF();
        hour = dataInput.readInt();
        num = dataInput.readInt();
        date = dataInput.readUTF();
    }

    public void set(String id, int hour, int num, String date) {
        this.id = id;
        this.hour = hour;
        this.num = num;
        this.date = date;
    }

    @Override
    public String toString() {
        return id+"\t"+date+"\t"+num;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getHour() {
        return hour;
    }

    public void setHour(int hour) {
        this.hour = hour;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }
}
